package com.pengliu.controller;


import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.pengliu.config.BaseController;
import com.pengliu.config.SysEnv;
import com.pengliu.util.Constants;

@Controller
@RequestMapping("/index")
public class IndexController extends BaseController{
	@RequestMapping("/welcome")
	public ModelAndView toWelomePage() throws UnknownHostException {
		
		Date dateTime = new Date();
		long startTime = (long) request.getServletContext().getAttribute(Constants.SYSRUNTIME);
		long runTime = (dateTime.getTime()-startTime)/1000/60;
		
		Properties props=System.getProperties();
		
		ModelAndView modelAndView = this.getModelAndView("/index/welcome");
		
		//系统环境
		Map<String, String> systemEnv = System.getenv();
		
		modelAndView.addObject("systemEnv", systemEnv);
        //本地IP
        modelAndView.addObject("ip", InetAddress.getLocalHost().getHostAddress());
        //端口
        modelAndView.addObject("port", SysEnv.port);
        //系统名称
        modelAndView.addObject("osName", props.getProperty("os.name"));
        //当前系统时间
        modelAndView.addObject("sysTime", DateFormatUtils.format(dateTime, "yyyy-MM-dd HH:mm:ss"));
        //系统运行分钟数
        modelAndView.addObject("runTime", runTime);
        //工作路径
        modelAndView.addObject("userDir", props.getProperty("user.dir"));
        //当前SessionId
        modelAndView.addObject("sessionId", request.getSession().getId());
        
		return modelAndView;
	}
	
	public static void main(String[] args) throws UnknownHostException {
		InetAddress addr = InetAddress.getLocalHost();   
        String ip=addr.getHostAddress().toString(); //获取本机ip
        
        System.out.println(ip);
	}
	
	
}
